package com.pioneer.gui.invoice.controller;

import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.text.JTextComponent;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.pioneer.beans.invoice.InvoiceHeaderModel;
import com.pioneer.gui.invoice.model.InvoiceModel;
import com.pioneer.gui.invoice.model.DropDownList;
import com.pioneer.gui.invoice.view.InvoicePanel;
import com.pioneer.gui.invoice.util.Constants;

public class InvoiceModeltoInvoicePanelAdapter
implements ChangeListener,Constants
{
	InvoiceModel model;
	InvoicePanel invoicePanel;
	
	public InvoiceModeltoInvoicePanelAdapter(InvoiceModel model, InvoicePanel invoicePanel)
	{
		this.model=model;
		this.invoicePanel=invoicePanel;
	}
	
	public void stateChanged(ChangeEvent e)
	{
		/*
		//InvoiceHeaderModel invoiceHeaderModel=this.model.getInvoiceHeader();
		
		
		// Update the customer drop down		
		Object[] dropDownValue=new Object[2]; 
		dropDownValue[0]=new Integer(this.model.getCusId());
		dropDownValue[1]=this.model.getName();		
		this.invoicePanel.customerPanel.customerDropDown.setSelectedItem(this.model.getName());		
		this.invoicePanel.customerPanel.customerDropDown.revalidate();
		this.invoicePanel.customerPanel.customerDropDown.repaint();
		
		// Update the salesperson drop down
		/*dropDownValue=new Object[2];
		dropDownValue[0]=new Integer(this.model.getSmanId());
		dropDownValue[1]=this.model.getSmanName();			
		this.invoicePanel.invoiceNoPanel.salesmanDropDown.setSelectedItem(this.model.getSmanName());			
		this.invoicePanel.invoiceNoPanel.salesmanDropDown.revalidate();
		this.invoicePanel.invoiceNoPanel.salesmanDropDown.repaint();
		
		// Update the invoice type drop down
		dropDownValue=new Object[2];
		dropDownValue[0]=this.model.getType();
		dropDownValue[1]=this.model.getTypeDesc();
		this.invoicePanel.invoiceNoPanel.invoiceType.setSelectedItem(this.model.getTypeDesc());
		this.invoicePanel.invoiceNoPanel.invoiceType.revalidate();
		this.invoicePanel.invoiceNoPanel.invoiceType.repaint();
				
		// Update the various text fields		
		
		Date invoiceDate=this.model.getDate();
		SimpleDateFormat dateFormat=new SimpleDateFormat();
		dateFormat.applyPattern("MM.dd.yyyy");
		this.invoicePanel.invoiceNoPanel.invoiceDate.setText(dateFormat.format(invoiceDate));
		
		this.invoicePanel.invoiceNoPanel.invoiceShipVia.setText(String.valueOf(this.model.getShipVia()));
		
		this.invoicePanel.invoiceNoPanel.invoiceStatus.setText(String.valueOf(this.model.getEntryStatusDesc()));
		
		//String billAddress=this.model.getBillAddress()+"\n"+this.model.getBillCity()+"\n"+this.model.getBillState()+"\n"+this.model.getBillZip();
		//String shipAddress=this.model.getShipAddress()+"\n"+this.model.getShipCity()+"\n"+this.model.getShipState()+"\n"+this.model.getShipZip();
		this.invoicePanel.addressPanel.billToAddressStreet.setText(this.model.getBillInfo()[InvoiceModel.ADDRESS]);
		this.invoicePanel.addressPanel.billToAddressCity.setText(this.model.getBillInfo()[InvoiceModel.CITY]);
		this.invoicePanel.addressPanel.billToAddressState.setText(this.model.getBillInfo()[InvoiceModel.STATE]);
		this.invoicePanel.addressPanel.billToAddressZip.setText(this.model.getBillInfo()[InvoiceModel.ZIP]);		
		this.invoicePanel.addressPanel.billToAddressPhone.setText(this.model.getBillInfo()[InvoiceModel.PHONE]);
		this.invoicePanel.addressPanel.billToAddressFax.setText(this.model.getBillInfo()[InvoiceModel.FAX]);
		this.invoicePanel.addressPanel.shipToAddressStreet.setText(this.model.getShipInfo()[InvoiceModel.ADDRESS]);
		this.invoicePanel.addressPanel.shipToAddressCity.setText(this.model.getShipInfo()[InvoiceModel.CITY]);
		this.invoicePanel.addressPanel.shipToAddressState.setText(this.model.getShipInfo()[InvoiceModel.STATE]);
		this.invoicePanel.addressPanel.shipToAddressZip.setText(this.model.getShipInfo()[InvoiceModel.ZIP]);
		this.invoicePanel.addressPanel.shipToAddressPhone.setText(this.model.getShipInfo()[InvoiceModel.PHONE]);
		this.invoicePanel.addressPanel.shipToAddressFax.setText(this.model.getShipInfo()[InvoiceModel.FAX]);
		this.invoicePanel.addressPanel.billToDropDown.setModel(new DropDownList(BILLING_LIST,String.valueOf(this.model.getCusId())));
		this.invoicePanel.addressPanel.shipToDropDown.setModel(new DropDownList(SHIPPING_LIST,String.valueOf(this.model.getCusId())));		
		
		this.invoicePanel.footerPanel.invoiceTerms.setText(String.valueOf( this.model.getTerms() ));
		
		this.invoicePanel.footerPanel.invoiceSubTotal.setText(String.valueOf( this.model.getSubTotal() ));		
		this.invoicePanel.footerPanel.invoiceDiscount.setText(String.valueOf( this.model.getDiscount() ));
		this.invoicePanel.footerPanel.invoiceTotal.setText(this.getTotal());
		this.invoicePanel.footerPanel.invoiceBalance.setText(String.valueOf( this.model.getBalance() ));
				
		String entryStatus=this.model.getEntryStatus();
		if ((entryStatus!=null)&&((entryStatus.equals(PAID))||(entryStatus.equals(SHIPPED))))
		{
			this.invoicePanel.footerPanel.navPanel.saveButton.setEnabled(false);
		}
		else
		{
			this.invoicePanel.footerPanel.navPanel.saveButton.setEnabled(true);
		}
		if ((entryStatus!=null)&&(entryStatus.equals(SHIPPED)))
		{
			this.invoicePanel.footerPanel.navPanel.shipButton.setEnabled(false);
		}
		else
		{
			this.invoicePanel.footerPanel.navPanel.shipButton.setEnabled(true);
		}
		this.model.setEditStatus(InvoiceModel.UNCHANGED);
		this.model.clearEditStatusMessage();*/
	}
	
	private String getTotal()
	{
		float total=this.model.getSubTotal()-this.model.getDiscount();
		return String.valueOf(total);
	}
		
	
	private void checkEditable(JButton button)
	{
		
	}
}